#coding=utf-8

from orm import Model, IntegerType, CharType, DatetimeType, Key, build_model
from settings import DEFAULT_USER_DB_NAME

@build_model
class Asset(Model):
    _table = 'asset'
    _name = '资产'
    _conn_name = DEFAULT_USER_DB_NAME
    id = IntegerType(name='id', comment='资产id', length=11, primary_key=True, unsigned=True, auto_increase=True)
    # 资产所有者id
    org_id = IntegerType(name='org_id', comment='资产所有者id', length=11, unsigned=True, blank=False)
    type_id = IntegerType(name='type_id', comment='资产类型id', length=11, unsigned=True, blank=False)
    # asset attribute json string
    location = CharType(name='location', comment='所在位置', length=50)
    asset_attr = CharType(name='asset_attr', comment='资产属性', length=255, varchar=True)
    asset_desc = CharType(name='asset_desc', comment='所在描述', length=255, varchar=True)
    asset_status = IntegerType(name='asset_status', comment='资产状态', length=3, blank=0, unsigned=True)
    # 时戳
    create_at = DatetimeType(name='create_at', comment='创建时间', auto='on_create')
    update_at = DatetimeType(name='update_at', comment='更新时间', auto='on_update')
    # 索引
    index_asset_org_id = Key(key_name='index_asset_org_id',col_name='org_id')
    index_asset_type_id = Key(key_name='index_asset_type_id',col_name='type_id')

@build_model
class AssetType(Model):
    _table = 'asset_type'
    _name = '资产类型'
    _conn_name = DEFAULT_USER_DB_NAME
    id = IntegerType(name='id', comment='资产类型id', length=11, primary_key=True, unsigned=True, auto_increase=True)
    type_name = CharType(name='type_name', comment='资产类型名', length=50, blank=False)
    # 时戳
    create_at = DatetimeType(name='create_at', comment='创建时间', auto='on_create')
    update_at = DatetimeType(name='update_at', comment='更新时间', auto='on_update')

@build_model
class AssetAttr(Model):
    _table = 'asset_attr'
    _name = '资产属性'
    _conn_name = DEFAULT_USER_DB_NAME
    id = IntegerType(name='id', comment='资产属性id', length=11, primary_key=True, unsigned=True, auto_increase=True)
    attr_name = CharType(name='attr_name', comment='资产属性名', length=50, blank=False)
    # 时戳
    create_at = DatetimeType(name='create_at', comment='创建时间', auto='on_create')
    update_at = DatetimeType(name='update_at', comment='更新时间', auto='on_update')

@build_model
class TypeAttr(Model):
    _table = 'type_attr'
    _name = '资产类型和资产属性对应关系表'
    _conn_name = DEFAULT_USER_DB_NAME
    id = IntegerType(name='id', comment='资产类型id', length=11, primary_key=True, unsigned=True, auto_increase=True)
    type_id = IntegerType(name='type_id', comment='资产类型id', length=11, unsigned=True, blank=False)
    attr_id = IntegerType(name='attr_id', comment='资产属性id', length=11, unsigned=True, blank=False)
    version = CharType(name='version', comment='对应关系版本', length=10, blank=False)
    # 时戳
    create_at = DatetimeType(name='create_at', comment='创建时间', auto='on_create')
    update_at = DatetimeType(name='update_at', comment='更新时间', auto='on_update')
    # 索引
    index_type_attr_type_id = Key(key_name='index_type_attr_type_id',col_name='type_id')
    
